from flask import Flask, render_template_string
import webbrowser
import threading
import time

app = Flask(__name__)

fake_error = """
<!DOCTYPE html>
<html>
<head>
    <title>系统错误</title>
    <style>
        body {
            background: #000;
            color: #0f0;
            font-family: 'Courier New', monospace;
            margin: 0;
            padding: 20px;
        }
        .error-box {
            border: 1px solid #f00;
            padding: 20px;
            background: #111;
        }
        .blink {
            animation: blink 1s infinite;
        }
        @keyframes blink {
            50% { opacity: 0; }
        }
        .scan-line {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 2px;
            background: #0f0;
            animation: scan 2s linear infinite;
        }
        @keyframes scan {
            0% { top: 0; }
            100% { top: 100%; }
        }
    </style>
</head>
<body>
    <div class="scan-line"></div>
    <div class="error-box">
        <h1>⚠️ 严重系统错误 ⚠️</h1>
        <p>> 检测到病毒入侵...</p>
        <p>> 系统文件损坏...</p>
        <p>> 内存泄漏 detected...</p>
        <p>> <span class="blink">正在删除重要文件...</span></p>
        <p>> 倒计时: <span id="countdown">10</span>秒</p>
    </div>
    
    <script>
        // 假倒计时
        var countdown = 10;
        var countdownElement = document.getElementById('countdown');
        
        var timer = setInterval(function() {
            countdown--;
            countdownElement.textContent = countdown;
            
            if (countdown <= 0) {
                clearInterval(timer);
                // 假的重启页面
                document.body.innerHTML = '<h1 style="text-align:center;margin-top:50px;">只是开玩笑的啦！😄</h1>';
            }
        }, 1000);
        
        // 随机错误信息
        var errors = [
            "kernel panic - not syncing",
            "segmentation fault",
            "out of memory",
            "file system corrupted",
            "hard drive failure imminent"
        ];
        
        setInterval(function() {
            var randomError = errors[Math.floor(Math.random() * errors.length)];
            var p = document.createElement('p');
            p.textContent = '> ' + randomError + '...';
            document.querySelector('.error-box').appendChild(p);
        }, 2000);
    </script>
</body>
</html>
"""

@app.route('/')
def index():
    return render_template_string(fake_error)

def open_browser():
    time.sleep(1)
    webbrowser.open('http://localhost:5000')

if __name__ == '__main__':
    threading.Thread(target=open_browser).start()
    app.run(host='0.0.0.0', port=5000, debug=False)